# date:20210223
from typing import List
import collections

# 运行时长：67%  内存：12%
class Solution:
    def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
        total_sum = sum([x for x, y in zip(customers, grumpy) if y == 0])
        max1 = roll = sum([x*y for x, y in zip(customers[:X], grumpy[:X])])
        for i in range(len(customers)-X):
            roll = roll - customers[i]*grumpy[i] + customers[i+X]*grumpy[i+X]
            max1 = max(max1, roll)
        return total_sum + max1




model = Solution()

customers = [1,0,1,2,1,1,7,5]
grumpy = [0,1,0,1,0,1,0,1]
X = 3
print(model.maxSatisfied(customers, grumpy, X))